#include "caller_filter.h"
#include "log.h"
#include "string_util.h"
#include "win_util.h"

bool CallerFilter::Handle(const ProcessInfo &process)
{
    auto parent = GetProcessName(process.ppid);
    if (parent.empty()) {
        auto err = GetLastError();
        LOG_ERR("get process parent {} failed. err: {}", process.ppid, err);
        return err == ERROR_ACCESS_DENIED;
    }
    for (auto &item : untrustedAppNameList) {
        if (FindIgnoreCase(parent, item)) {
            LOG_DEBUG("process caller {} is untrusted.", UnicodeToUtf8(parent));
            return false;
        }
    }
    return true;
}

void CallerFilter::Update()
{}